/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javafxapplication1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author my
 */
public class Profile {

    static Properties props;
    static File file = new File("profile.ini");

    static {
        if (props == null) {
            props = new Properties();

            try {

                if (file.exists()) {
                    props.load(new FileInputStream(file));
                } else {

                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private Profile() {

    }

    public static String get(String key) {
        return props.getProperty(key);
    }

    public static String get(String key, String defaultVal) {
        if (props.containsKey(key)) {
            return props.getProperty(key);
        } else {
            return defaultVal;
        }
    }

    public static void put(String key, String val) {
        props.put(key, val);
    }

    public static void save() {
        try {
            props.store(new FileOutputStream(file), "");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Profile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
